# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

_realname=recode
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=3.7.6
pkgrel=2
pkgdesc="Converts files between various character sets and usages (mingw-w64)"
arch=('any')
url="http://recode.progiciels-bpi.ca/index.html"
license=('GPL3' 'LGPL')
depends=("${MINGW_PACKAGE_PREFIX}-gettext")
options=('!strip' 'staticlibs')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-python3")
source=("https://github.com/rrthomas/recode/releases/download/v${pkgver}/${_realname}-${pkgver}.tar.gz"
        01-no-undefined.patch)
sha256sums=('46c5828ac6f5fb759ecf98b16a674188d901b84675b0dbbc0afc03c542d3a954'
            '21de31138709ec460fb684b5bf110beabf31627b8e55b4131aad67c7633e77dd')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/01-no-undefined.patch

  autoreconf -fiv
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}

  export lt_cv_deplibs_check_method='pass_all'

  PYTHON="${MINGW_PREFIX}/bin/python3" \
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --mandir=${MINGW_PREFIX}/share/man \
    --infodir=${MINGW_PREFIX}/share/info \
    --without-libiconv-prefix \
    --without-libintl-prefix

  make
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR="${pkgdir}" install

  mkdir -p ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/COPYING "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/COPYING-LIB "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING-LIB"
}
